cpu=`uname -m`
echo $cpu
enodeName="enode"
updateName="update"

if [ "x86_64" == $cpu ];then
  enodeName="enode"
else
  enodeName="enode_arm64"
  updateName="update_arm"
fi

P2P=$(ps -ef | grep P2PTunnelServer | grep -v "grep" | wc -l)
echo $P2P
if [ $P2P -eq 0 ]; then
	echo "not p2p found"
else
	echo "p2p found"
fi

mkdir -p /data_dir/enode
mkdir -p /opt/enode
cd /opt/enode

#下载程序
rm -f $enodeName && wget http://101.37.33.124/$enodeName
rm -f $updateName && wget http://101.37.33.124/$updateName

if [ "x86_64" != $cpu ];then
  mv $enodeName enode
  mv $updateName update
fi
chmod +x enode
chmod +x update

#安装
if [ ! -f /root/.local/share/enode/config.yaml ];then
		echo "to setup enode"
		if [ $P2P -eq 0 ];then
        read -p "input devid: " devid
        echo $devid
        ./enode setup --dev-id=$devid
    else
        ./enode setup
    fi

		echo "setup ok"
else
		echo "setup exist"
fi

pkill -9 update
pkill -9 enode
echo "start enode "
nohup /opt/enode/enode run > /opt/enode/1.log 2>&1 &
echo "start update "
nohup ./update &
echo "启动ok"